﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using AssessmentTool.PresentationLogic;
using ModelLayer;
using System.Linq;
using AssessmentTool.PresentationLogic.EventArguments;


namespace AssessmentTool
{
	public partial class Competenza : UserControl,IContainer
	{
        private ModelLayer.Competenza competenza;
        private IContainer parent;

		public Competenza()
		{
			// Required to initialize variables
			InitializeComponent();
            
		}
        public void initWithCompetenza(ModelLayer.Competenza competenza)
        {
            this.competenza = competenza;
            CodiceCompetenza.Text = competenza.Codice ;
            TestoCompetenza.Text = new ApplicationResources().Get(competenza.Codice);
            scelta.initWithCompetenza(competenza,this);
            scelta.Name = competenza.Codice + "scelta";
            this.Name = competenza.Codice;
        }

        

        public void setIContainerParent(IContainer parent)
        {
            this.parent = parent;
        }


        public void addChild(UserControl control)
        {
            throw new NotImplementedException();
        }



        public void addMaximumProgress()
        {
            parent.addMaximumProgress();
        }

        public void addProgress()
        {
            parent.addProgress();
        }

        private void Image_MouseEnter(object sender, MouseEventArgs e)
        {
            Point p=e.GetPosition(null);
            double x=p.X+40;
            double y=p.Y-70;
            EventDispatcher.getInstance().dispatch("SHOWHELP", new ShowHelpEventArgs() { ShowModal = true, Width = 400, Height = 150, Margin = new Thickness(x, y, 0, 0), Text = new ApplicationResources().Get(competenza.Codice + ".HELP"),Titolo=CodiceCompetenza.Text+" "+TestoCompetenza.Text });
        }

        private void Image_MouseLeave(object sender, MouseEventArgs e)
        {
            EventDispatcher.getInstance().dispatch("CLOSEMODAL", null);
        }

        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            EventDispatcher.getInstance().dispatch("SHOWHELP", new ShowHelpEventArgs() { ShowModal = false, Width = 600, Height = 480, Text = new ApplicationResources().Get(competenza.Codice + ".HELP"), Titolo = CodiceCompetenza.Text + " " + TestoCompetenza.Text });
        }


        public void enableRisposta(bool enable)
        {
            scelta.IsEnabled = enable;
        }
    }
}